#include "mainwindow.h"
#include "ui_mainwindow.h"

void MainWindow::intUI()
{
    label = new QLabel;
    label -> setMidLineWidth(150);
    label -> setText("当前文件");
    ui->statusBar->addWidget(label);
    progressbar = new QProgressBar;
    progressbar -> setMinimum(5);
    progressbar -> setMaximum(50);
    progressbar -> setValue(ui -> textEdit -> font().pointSize());
    ui -> statusBar -> addWidget(progressbar);
    spinbox = new QSpinBox;
    ui -> mainToolBar -> addWidget(new QLabel("字体大小"));
    ui -> mainToolBar -> addWidget(spinbox);
    fontcombobox = new QFontComboBox;
    ui -> mainToolBar -> addWidget(new QLabel("字体"));
    ui -> mainToolBar -> addWidget(fontcombobox);
}

void MainWindow::lianjie()
{
    connect(spinbox,SIGNAL(valueChanged(int)),
            this,SLOT(on_spinBoxFontSize_valueChanged(int)));

    connect(fontcombobox,SIGNAL(currentIndexChanged(const QString&)),
            this,SLOT(on_comboFont_currentIndexChanged(const QString&)));
}

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    intUI();
    lianjie();
    setCentralWidget(ui->textEdit);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_actioncuti_triggered(bool checked)
{
    QTextCharFormat fff;
    fff=ui->textEdit->currentCharFormat();
    if(checked)
    {
        fff.setFontWeight(QFont::Bold);
    }
    else
    {
        fff.setFontWeight(QFont::Normal);
    }
    ui ->textEdit->mergeCurrentCharFormat(fff);

}

void MainWindow::on_spinBoxFontSize_valueChanged(int aFontSize)
{
    QTextCharFormat fff;
    fff.setFontPointSize(aFontSize);
    ui ->textEdit ->mergeCurrentCharFormat(fff);
    progressbar->setValue(aFontSize);
}

void MainWindow::on_comboFont_currentIndexChanged(const QString &argl)
{
    QTextCharFormat fff;
    fff.setFontFamily(argl);
    ui->textEdit->mergeCurrentCharFormat(fff);
}


void MainWindow::on_actionxieti_triggered(bool checked)
{
    QTextCharFormat fff;
    fff=ui->textEdit->currentCharFormat();
    if(checked)
    {
        fff.setFontItalic(QFont::Bold);
    }
    else
    {
        fff.setFontItalic(QFont::StyleNormal);
    }
    ui ->textEdit->mergeCurrentCharFormat(fff);
}

void MainWindow::on_actionxiahuaxian_triggered(bool checked)
{
    QTextCharFormat fff;
    fff=ui->textEdit->currentCharFormat();
    if(checked)
    {
        fff.setFontUnderline(QFont::Bold);
    }
    else
    {
        fff.setFontUnderline(QFont::StyleNormal);
    }
    ui ->textEdit->mergeCurrentCharFormat(fff);
}
